import scipy
from scipy.sparse import dok_matrix

# 创建dok_matrix
dok = dok_matrix((4, 4), dtype=int)
dok[0, 0] = 3
dok[0, 2] = 8
dok[1, 1] = 2
dok[3, 3] = 1

print("DOK Matrix:")
print(dok.toarray())
from scipy.sparse import lil_matrix

# 创建lil_matrix
lil = lil_matrix((4, 4), dtype=int)
lil[0, 0] = 3
lil[0, 2] = 8
lil[1, 1] = 2
lil[3, 3] = 1

print("LIL Matrix:")
print(lil.toarray())
from scipy.sparse import coo_matrix

# 定义非零元素的坐标和值
data = [3, 8, 2, 1]  # 非零元素的值
row_indices = [0, 0, 1, 3]  # 非零元素的行索引
col_indices = [0, 2, 1, 3]  # 非零元素的列索引

# 创建coo_matrix
coo = coo_matrix((data, (row_indices, col_indices)), shape=(4, 4), dtype=int)

print("COO Matrix:")
print(coo.toarray())
help(scipy.sparse.dok_matrix)
help(scipy.sparse.lil_matrix)
help(scipy.sparse.coo_matrix)